package com.zh.jetpackmvvm.util

import android.annotation.SuppressLint
import android.content.Context
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CircleCrop
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.bumptech.glide.request.RequestOptions

/**
 * @author :zhouh
 * email：zhouhe@sixarm.cn
 * time：2020-06-03
 * company：山东六臂网络科技有限公司
 * desc：
 */
object GlideUtil {

    /**
     * 加载普通图片
     */
    @SuppressLint("CheckResult")
    fun loadImage(context: Context, url: String, img: ImageView, withCrossFade: Boolean = true) {
        val glideBuilder = Glide.with(context).load(url)
        if (withCrossFade) {
            glideBuilder.transition(DrawableTransitionOptions.withCrossFade(500))
        }
        glideBuilder.into(img)
    }

    /**
     * 加载圆形图片
     */
    @SuppressLint("CheckResult")
    fun loadCircleImage(context: Context, url: String, img: ImageView, withCrossFade: Boolean = true){
        val glideBuilder = Glide.with(context).load(url)
        if (withCrossFade) {
            glideBuilder.transition(DrawableTransitionOptions.withCrossFade(500))
        }
        glideBuilder.apply(RequestOptions.bitmapTransform(CircleCrop())).into(img)
    }
}